package com.qidianit.mes.production.controller;

import com.qidianit.mes.common.pojo.MesResult;
import com.qidianit.mes.pojo.Material;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;

/**
 * @author 戴着假发的程序员
 * @company 起点编程
 * @date 2025/7/29 10:45
 * @description
 */
@RestController
@RequestMapping("/production")
@CrossOrigin
public class ProductionController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private WebClient.Builder builder;
    @GetMapping("/getMaterial/{materialId}")
    public MesResult<Material> getMaterial(@PathVariable String materialId)
    {
        // 通过builder来创建WebClient对象
       return builder.build().get()
                .uri("/master/materials/" + materialId)
                .retrieve()
                .bodyToMono(MesResult.class).block();
    }

    //    @GetMapping("/getMaterial/{materialId}")
//    public MesResult<Material> getMaterial(@PathVariable String materialId)
//    {
//        // 通过 restTemplate直接进行远程调用  这里的url理论上基础部分应该是在配置文件中配置
//        MesResult result = restTemplate.getForObject("http://localhost:11011/master/materials/" + materialId, MesResult.class);
//        return result;
//    }

    @RequestMapping("/test")
    public String test()
    {
        return "hello world production";
    }
}
